package com.test.dao.impl;

import com.test.dao.HistoryOrderHaveDao;
import com.test.domain.HistoryOrderHave;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class HistoryOrderHaveDaoImpl implements HistoryOrderHaveDao {
    @Resource
    private JdbcTemplate jdbcTemplate;


    @Override
    public List<HistoryOrderHave> getDishListByHistoryOrderNumber(String historyOrderNumber) {
        String sql = "select * from V_history_have where history_order_number=?";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<HistoryOrderHave>(HistoryOrderHave.class), historyOrderNumber);
    }

    @Override
    public int updateGradeByHistoryNumberAndDishNumber(String historyOrderNumber, Integer orderDishGrade, String dishNumber) {
        String sql="select order_dish_grade from history_order_have where history_order_number=? and dish_number=?";
        List<String> list = jdbcTemplate.queryForList(sql, String.class, historyOrderNumber,dishNumber);
        String temp=list.get(0);
        if(temp==null){
            String sql_temp="update history_order_have set order_dish_grade =? where history_order_number=? and dish_number=?";
            jdbcTemplate.update(sql_temp,orderDishGrade,historyOrderNumber,dishNumber);
            return 1;
        }else return 0;
    }


}
